package com.tencent.sr.iris.basic.saas.common.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public enum IrisTaskTypeEnum {
    INVITE_NEW_FIRST_PURCHASE(Arrays.asList(1), "邀新有礼"),

    GMV_SPRINT(Arrays.asList(3), "GMV冲刺赛"),

    SALES_VOLUME_SPRINT(Arrays.asList(4), "销量冲刺赛"),

    /**
     * 佣金回滚，包含类型5，6，7
     */
    COMMISSION_ROLLBACK(Arrays.asList(5, 6, 7), "佣金回滚"),
    
    FIRST_ORDER(Arrays.asList(8), "粉丝首单"),
    
    AWARD_TOOL(Arrays.asList(9), "派奖工具"),

    NORMAL_GROUP(Arrays.asList(10), "普通团推团"),

    SPECIAL_GROUP(Arrays.asList(11), "特邀团推团"),
    
    GMV_SPRINT_MAGNIFY(Arrays.asList(12), "GMV-佣金翻倍"),
    
    SALES_VOLUME_SPRINT_MAGNIFY(Arrays.asList(13), "销售件数-佣金翻倍"),

    GMV_RANK(Arrays.asList(14), "GMV（排行榜）"),

    COMMISSION_RANK(Arrays.asList(15), "佣金（排行榜）"),

    SPECIAL_SPRINT(Arrays.asList(20), "特邀会员冲刺赛"),

    SALE_SPRINT(Arrays.asList(21), "多目标冲刺赛"),

    NEW_SALE_SPRINT(Arrays.asList(23), "新版多目标冲刺赛"),


    ;

    /**
     * 任务类型
     */
    private List<Integer> codes;

    /**
     * 描述
     */
    private String desc;

    IrisTaskTypeEnum(List<Integer> codes, String desc) {
        this.codes = codes;
        this.desc = desc;
    }

    public List<Integer> getCodes() {
        return codes;
    }

    public String getDesc() {
        return desc;
    }

    public static String getByType(Integer code) {
        IrisTaskTypeEnum enumByType = getEnumByType(code);
        return Optional.ofNullable(enumByType)
                .map(IrisTaskTypeEnum::getDesc).orElse(StringUtils.EMPTY);
    }

    public static IrisTaskTypeEnum getEnumByType(Integer code) {
        for (IrisTaskTypeEnum taskTypeEnum : IrisTaskTypeEnum.values()) {
            if (taskTypeEnum.getCodes().contains(code)) {
                return taskTypeEnum;
            }
        }
        return null;
    }
}
